package com.ynet.hmds28.service.mq;

import java.util.Properties;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.aliyun.openservices.ons.api.bean.ProducerBean;

@Configuration
public class AliMQConfig {
    @Value("${producerId}")
    public String producerId;

    @Value("${consumerId}")
    public String consumerId;

    @Value("${accessKey}")
    public String accessKey;

    @Value("${secretKey}")
    public String secretKey;

    @Value("${onsAddr}")
    public String onsAddr;

    //超时时间
    @Value("${sendMsgTimeoutMillis}")
    public String sendMsgTimeoutMillis;

    @Value("${suspendTimeMillis}")
    public String suspendTimeMillis;

    @Value("${maxReconsumeTimes}")
    public String maxReconsumeTimes;

    @Bean(initMethod = "start", destroyMethod = "shutdown")
    public ProducerBean getProducer() {
        ProducerBean producerBean = new ProducerBean();
        Properties properties = new Properties();
        properties.put(PropertyKeyConst.ProducerId, producerId);
        // AccessKey 阿里云身份验证，在阿里云服务器管理控制台创建
        properties.put(PropertyKeyConst.AccessKey, accessKey);
        // SecretKey 阿里云身份验证，在阿里云服务器管理控制台创建
        properties.put(PropertyKeyConst.SecretKey, secretKey);
        properties.put(PropertyKeyConst.SendMsgTimeoutMillis, sendMsgTimeoutMillis);
        properties.put(PropertyKeyConst.ONSAddr, onsAddr);
        producerBean.setProperties(properties);
        return producerBean;
    }

}
